#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int n; cin >> n;
    vector<int> arr(n);
    for (auto& e : arr) cin >> e;

    int pos, id, jug = 0;
    while (cin >> pos >> id)
    {
        if (jug)cout << endl; jug = 1;
        if (pos <= 0 || pos > arr.size() + 1)
            cout << "invalid";
        else
        {
            if (pos == arr.size() + 1) arr.push_back(id);
            else arr.insert(arr.begin() + pos - 1, id);
            for (int i = 0; i < arr.size(); i++)
            {
                if (i) cout << ' ';
                cout << arr[i];
            }
        }
    }

    return 0;
}